// pages/group/order-list.js
var util = require('../../utils/util.js')

var sliderWidth = 96; // 需要设置slider的宽度，用于计算中间位置
Page({

  /**
   * 页面的初始数据
   */
  data: {
    paging: { height: 0, page: 1, limit: 20, totalPage: 0 },
    orderList: [],
    status: "",
    groupList:[],
    //所有，1待付款，2已完成，3已取消
    tabs: [
      { name: "我参与的", key: "0" },
      { name: "我发布的", key: "1" },
      { name: "接龙订单", key: "2" }
    ],
    activeIndex: 0,
    sliderOffset: 0,
    sliderLeft: 0
  },
  viewGrou: function (e) {
    var groupId = e.currentTarget.dataset.solitaireId;
    wx.navigateTo({
      url: '/pages/group/group-info?groupId=' + groupId,
      fail: function (e) {
        console.log(e);
      }
    })
  },
  deleteOrder: function (e) {
    var orderId = e.currentTarget.dataset.orderid;
    var that = this;
    util.gets({
      uri: '',
      success: function (r) {
        that.getData();
      }
    });

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '接龙记录',
    });
    var that = this;
    wx.getSystemInfo({
      success: (res) => {
        that.setData({
          "paging.height": res.windowHeight
        })
      }
    })
    this.getData();
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
          sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
        });
      }
    });
  },
  tabClick: function (e) {
    this.setData({
      sliderOffset: e.currentTarget.offsetLeft,
      activeIndex: e.currentTarget.id,
      orderList: [],
      groupList: []
    });
    this.getData();
  },
  nextPage: function () {
    var that = this;
    util.nextPage(function (param) {
      that.getData(param);
    });
  },
  getData: function (param) {
    if (!param) {
      param = {};
    }
    var uri="";
    var dataList="";
    switch(parseInt(this.data.activeIndex)){
      case 0:
      case 1:
        uri ="/solitaire/solitaire/list";
        param["activeIndex"] = this.data.activeIndex;
        dataList ="groupList";
        break;
      case 2:
        uri ="/group/order/list";
        dataList = "groupList";
        break;
      default:
        return;
    }
   
    util.pagingPost({
      uri: uri,
      params: param,
      dataList: dataList
    });

  },
  toSolitaireInfo: function (e) {
    var solitaireId = e.currentTarget.dataset.solitaireid;
    var type = e.currentTarget.dataset.type;
    var url ="";
    switch(type){
      case "1":
        url = "../group/group-info?groupId=" + solitaireId;
        break;
      case "2":
        url = "../activity/activity-info?activityId=" + solitaireId;
        break;
      case "3":
        url = "../form/form-info?formId=" + solitaireId;
        break;
      default:
        return;
    }
    wx.navigateTo({
      url: url,
      fail: function (e) {
        console.log(e);
      }
    })
  },
  toSolitaireEdit: function (e) {
    var solitaireId = e.currentTarget.dataset.solitaireid;
    var type = e.currentTarget.dataset.type;
    var url = "";
    switch (type) {
      case "1":
        url = "../group/group-edit?groupId=" + solitaireId;
        break;
      case "2":
        url = "../activity/activity-edit?activityId=" + solitaireId;
        break;
      case "3":
        url = "../formform-edit?formId=" + solitaireId;
        break;
      default:
        return;
    }
    wx.navigateTo({
      url: url,
      fail: function (e) {
        console.log(e);
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})